package com.jxsm.controller;

import com.jxsm.pojo.Export;
import com.jxsm.service.ExportService;
import com.jxsm.service.ExtCProductService;
import com.jxsm.service.export.ExportProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/9.
 */
@Controller
public class ExportController extends BaseController {
    @Autowired
    private ExportService exportService;
    @Autowired
    private ExportProductService exportProductService;
    @RequestMapping("/cargo/contract/export/exportlist.action")
    public String find (Map<String,Object>map){
        map.put("list",exportService.find(null));
        return  "/cargo/contract/export/exportlist.jsp";
    }
    //查看启用状态的购销合同
    @RequestMapping("/cargo/contract/export/exportcontractlist.action")
    public String selectContract(Map<String,Object>map){
        Map map1=new HashMap();
        map1.put("state",1);
        map.put("contracts",exportService.contract(map1));
        return  "/cargo/contract/export/exportcontract.jsp";
    }
    @RequestMapping("/cargo/export/insert.action")
    public String insert(String [] id){
        exportService.insert(id);
        return "redirect:/cargo/contract/export/exportcontractlist.action";
    }
    @RequestMapping("/cargo/contract/export/deleteById.action")
    public String deletebyid(String id){
        exportService.deleteById(id);
        return "redirect:/cargo/contract/export/exportlist.action";
    }
    @RequestMapping("/cargo/contract/export/delete.action")
    public String delete(String [] id){
        exportService.deleteExport(id);
        return "redirect:/cargo/contract/export/exportlist.action";
    }
    @RequestMapping("/cargo/contract/export/toupdate.action")
    public String toupdate(String id,Map<String,Object>map){
        Export obj = exportService.getExport(id);
        map.put("obj", obj);
        map.put("mRecordData",exportProductService.exportproducts(id));
        return "\\cargo\\contract\\export\\ExportUpdate.jsp";
    }
    @RequestMapping()
    public String updateEp( Export exports,String[] mr_id,
                           Integer[] mr_orderNo,
                           Integer[] mr_cnumber,
                           Double[] mr_grossWeight,
                           Double[] mr_netWeight,
                           Double[] mr_sizeLength,
                           Double[] mr_sizeWidth,
                           Double[] mr_sizeHeight,
                           Double[] mr_exPrice,
                           Double[] mr_tax,
                           Integer[] mr_changed,Map<String,Object>map){
        map.put("id",exports.getId());
        exportService.updateExport(exports);

        exportService.updateExportProduct(mr_id,mr_orderNo,mr_cnumber,mr_grossWeight,
                                            mr_netWeight,mr_sizeLength, mr_sizeWidth,
                                            mr_sizeHeight,mr_exPrice,mr_tax,mr_changed);
        return "redirect:/cargo/contract/export/toupdate.action";
    }
}
